package com.wang.mandkey.views;

import android.content.Context;
import android.graphics.Color;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.SurfaceHolder;
import android.view.SurfaceView;

public class MouseClickView extends SurfaceView implements
		SurfaceHolder.Callback {

	private boolean canDraw = false;
	private Context mContext;
	private PressListener pressListener;

	public MouseClickView(Context context, AttributeSet atrset) {
		super(context, atrset);
		mContext = context;
		setBackgroundColor(Color.LTGRAY);
	}

	@Override
	public boolean onTouchEvent(MotionEvent event) {
		int action = event.getAction();
		switch (action) {
		case MotionEvent.ACTION_DOWN: {
			setBackgroundColor(Color.YELLOW);
			if (null != pressListener) {
				pressListener.onPresess();
			}
			return true;
		}
		case MotionEvent.ACTION_UP: {
			setBackgroundColor(Color.LTGRAY);
			if (null != pressListener) {
				pressListener.onRelease();
			}
		}
			break;
		default:
			break;
		}
		return true;
	}

	public PressListener getPressListener() {
		return pressListener;
	}

	public void setPressListener(PressListener pressListener) {
		this.pressListener = pressListener;
	}

	@Override
	public void surfaceCreated(SurfaceHolder holder) {
		canDraw = true;

	}

	@Override
	public void surfaceChanged(SurfaceHolder holder, int format, int width,
			int height) {
	}

	@Override
	public void surfaceDestroyed(SurfaceHolder holder) {
	}

	public static interface PressListener {
		public void onPresess();

		public void onRelease();
	}
}
